<?php

/**
 * Персональная страница
 *
 * @package    sf_sandbox
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class Type2Form extends BaseMaterialForm
{
  public function configure()
  {
  	
  		unset( 
  		$this['created_at'],  
  		$this['updated_at'],  
  		$this['user_id'], 
  		$this['click'], 
  		$this['country'],
  		$this['custom_int3'],
  		$this['custom_text1'],
  		$this['custom_text2'],
  		$this['custom_text3'],
  		$this['custom_char2'],
  		$this['custom_char3'],
  		$this['seo_title'],
  		$this['seo_keyword'],
  		$this['stat'],
  		$this['city']);
  		
  		
  		
  		$this->setWidgets(array(
      'id'               => new sfWidgetFormInputHidden(),
      'type_id'           => new sfWidgetFormInputHidden(array(), array('value' =>'2', 'class'=>'test')),
  	  'parent_id'         => new sfWidgetParentMaterial(),	
  	  'content' => new sfWidgetFormTextareaNickEdit(array(),array('class'   =>  'material_content','style'=>'width:620px')),
  	  'photo_path' => new inputImageTag (  array (), array('mat_id'=>$this->object->getId(),'folder'=>'personal_page') ), 
  	  'custom_bool1'      => new sfWidgetFormInputCheckbox(),
  	  'link'              => new sfWidgetFormInput()
  	 
    ));
  		
    /*
     *'content' => new sfWidgetFormTextareaTinyMCE(array(),array('class'=>'material_content','width'=>'600px')),
     *  
     */
  		
  		$this->widgetSchema->setLabels(array(  
  		'content'   => 'Содержимое',
  		'parent_id'   => 'Пренадлежность',
  		 'photo_path'   => 'Фоновый рисунок',
  		 'custom_bool1'   => 'Конт. информация',
  		 'link'   => 'Ссылка',
  	 ));
  		

  		 $this->validatorSchema['photo_path'] = new sfValidatorFile(array(
        'required'   => false,
        'path'       => sfConfig::get('sf_web_dir').'/uploads/personal_page',
        'mime_types' => 'web_images',
        'max_size'   => 380000, // 360 kB,
  		
        )); 
  	
       
        $this->validatorSchema->setOption('allow_extra_fields', true);    
  		 
  		 $this->widgetSchema->setNameFormat('material[%s]');	 
  		 
  		//    $js_path = '/js/tinymce/tiny_mce.js';
        //    sfContext::getInstance()->getResponse()->addJavascript($js_path);
            
        
            
            
  
  }
  
  
 public function save($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (is_null($con))
    {
      $con = $this->getConnection();
    }

    try
    {
      $con->beginTransaction();

      $this->doSave($con);

      $con->commit();
    }
    catch (Exception $e)
    {
      $con->rollBack();

      throw $e;
    }

    $o = $this->getObject();
    $c = new Criteria();
    $c->add(Material2MaterialPeer::FROM_ID,$o->getParentId());
    $c->addAnd(Material2MaterialPeer::TO_ID,$o->getId());
    $cnt = Material2MaterialPeer::doCount($c);
    if($cnt==0)
    {    
  	$f = new Material2Material();
  	$f->setFromId($o->getParentId());
  	$f->setToId($o->getId());
  	$f->save();
    }
    return $this->object;
  }
  
  
  function TypeFormatter($widget, $inputs)
  {
    
    return $str;
  }
  
   
}
